package com.health.web.controller.teahouse;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.teahouse.domain.ExerciseData;
import com.health.teahouse.service.IExerciseDataService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 运动数据管理Controller
 * 
 * @author yang
 * @date 2024-02-11
 */
@RestController
@RequestMapping("/teahouse/sportsData")
public class ExerciseDataController extends BaseController
{
    @Autowired
    private IExerciseDataService exerciseDataService;

    /**
     * 查询运动数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:sportsData:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExerciseData exerciseData)
    {
        startPage();
        List<ExerciseData> list = exerciseDataService.selectExerciseDataList(exerciseData);
        return getDataTable(list);
    }

    /**
     * 导出运动数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:sportsData:export')")
    @Log(title = "运动数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExerciseData exerciseData)
    {
        List<ExerciseData> list = exerciseDataService.selectExerciseDataList(exerciseData);
        ExcelUtil<ExerciseData> util = new ExcelUtil<ExerciseData>(ExerciseData.class);
        util.exportExcel(response, list, "运动数据管理数据");
    }

    /**
     * 获取运动数据管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:sportsData:query')")
    @GetMapping(value = "/{dataId}")
    public AjaxResult getInfo(@PathVariable("dataId") Long dataId)
    {
        return success(exerciseDataService.selectExerciseDataByDataId(dataId));
    }

    /**
     * 获取统计数据
     */
    //@PreAuthorize("@ss.hasPermi('teahouse:sportsData:query')")
    @GetMapping(value = "/echart")
    public AjaxResult echartData(@RequestParam("userId") Long userId,@RequestParam("date")String date)
    {

        return success(exerciseDataService.selectEchartData(userId,date));

    }

    /**
     * 新增运动数据管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:sportsData:add')")
    @Log(title = "运动数据管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExerciseData exerciseData)
    {
        return toAjax(exerciseDataService.insertExerciseData(exerciseData));
    }

    /**
     * 修改运动数据管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:sportsData:edit')")
    @Log(title = "运动数据管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExerciseData exerciseData)
    {
        return toAjax(exerciseDataService.updateExerciseData(exerciseData));
    }

    /**
     * 删除运动数据管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:sportsData:remove')")
    @Log(title = "运动数据管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dataIds}")
    public AjaxResult remove(@PathVariable Long[] dataIds)
    {
        return toAjax(exerciseDataService.deleteExerciseDataByDataIds(dataIds));
    }
}
